package com.cefa.finance.controller;

import com.cefa.finance.model.RepaymentRecord;
import com.cefa.finance.result.ResultModel;
import com.cefa.finance.service.RepaymentInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("repaymentInfo")
public class RepaymentInfoController {

    private static final Logger logger = LoggerFactory.getLogger(RepaymentInfoController.class);

    @Autowired
    private RepaymentInfoService repaymentInfoService;

    @RequestMapping(path = "addPaymentRecord", method = RequestMethod.POST)
    @CrossOrigin
    public ResultModel addPaymentRecord(RepaymentRecord repaymentRecord) {
        try {
            return repaymentInfoService.addPaymentRecord(repaymentRecord);
        } catch (Exception e) {
            logger.error(e.getMessage());
            return ResultModel.ERROR(e.getMessage());
        }
    }

    @RequestMapping(path = "updatePaymentRecord", method = RequestMethod.POST)
    @CrossOrigin
    public ResultModel updatePaymentRecord(RepaymentRecord repaymentRecord) {
        try {
            return repaymentInfoService.addPaymentRecord(repaymentRecord);
        } catch (Exception e) {
            logger.error(e.getMessage());
            return ResultModel.ERROR(e.getMessage());
        }
    }

    @RequestMapping(path = "deletePaymentRecord", method = RequestMethod.POST)
    @CrossOrigin
    public ResultModel deletePaymentRecord(RepaymentRecord repaymentRecord) {
        try {
            return repaymentInfoService.deletePaymentRecord(repaymentRecord);
        } catch (Exception e) {
            logger.error(e.getMessage());
            return ResultModel.ERROR(e.getMessage());
        }
    }

    @RequestMapping(path = "listPaymentInfo", method = RequestMethod.POST)
    @CrossOrigin
    public ResultModel listPaymentInfo(String searchText, Integer pageNo, Integer pageCount) {
        try {
            return repaymentInfoService.listPaymentInfo(searchText,pageNo,pageCount);
        } catch (Exception e) {
            logger.error(e.getMessage());
            return ResultModel.ERROR(e.getMessage());
        }
    }
}
